#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <string.h>
// gcc CAPI.c -o capi -llua -ldl -lm
int main( void )
{
    char buff[256];
    int error;
    // 创建一个用于c与lua交互的栈
    lua_State *L  = luaL_newstate();
    if(!L)
        printf("luaL_newstate fail \n");
    printf("luaL_newstate ok \n");
    luaopen_base(L); /* opens the basic library */
    luaopen_table(L); /* opens the table library */
    luaopen_io(L);   /*opens the I/O library */
    luaopen_string(L);  /* opens the string lib. */
    luaopen_math(L); /* opens the math lib. */
    while (fgets(buff, sizeof(buff), stdin) != NULL) {
    error = luaL_loadbuffer(L, buff, strlen(buff),
    "line") || lua_pcall(L, 0, 0, 0);
    if (error) 
    {
        fprintf(stderr, "%s", lua_tostring(L, -1));
        lua_pop(L, 1);/* pop error message from the stack */
    }
    }
    lua_close(L);
}